/*
 * QStyleManager.cpp  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "QStyleManager.h"

#include "QApplicationAdapter.h"
#include "QApplicationDelegate.h"
#include "QWindowsClassicStyle.h"

#ifdef Q_OS_WIN32
  #include "Cute4jWin32.h"
  #include "QWindowsNativeStyle.h"
#endif // Q_OS_WIN32

// QStyleManager :: Private Constructor. ---------------------------------------

QStyleManager::QStyleManager()
  : m_systemStyleName(QApplication::style()->objectName()),
    m_availableStyleNames(QStyleFactory::keys()),
    m_systemPallete(QApplication::palette()), m_useSystemTheme(false)
{
  #ifdef Q_OS_WIN32
    m_winThemeable = Cute4j::Platform::Win32::IsThemeAvailable();
    QWindowsNativeStyle::initialize(m_winThemeable);
    if (!QApplicationDelegate::argvContains("-style", 6)) {
      qApp->setStyle(new QWindowsNativeStyle());
    }
    if (m_winThemeable) {
      Cute4j::Platform::Win32::EnableTheme();
      if (QSysInfo::WindowsVersion == QSysInfo::WV_XP) {
        m_systemPallete.setColor(QPalette::All, QPalette::Button,
                                 QColor(255, 255, 255, 255));
        m_systemPallete.setColor(QPalette::All, QPalette::Light,
                                 QColor(255, 255, 255, 255));
      }
    }
  #endif // Q_OS_WIN32
  for (int i = m_availableStyleNames.size(); --i >= 0;) {
    if (m_systemStyleName == m_availableStyleNames[i].toLower()) {
      m_systemStyleName = m_availableStyleNames[i];
      #ifdef Q_OS_WIN32
        if (!m_winThemeable &&
            m_systemStyleName.startsWith(QLatin1String("Windows"))) {
          m_systemStyleName = "Windows";
        } else if (m_systemStyleName == QLatin1String("WindowsXP")) {
          m_systemStyleName = "Windows XP";
        } else if (m_systemStyleName == QLatin1String("WindowsVista")) {
          m_systemStyleName = "Windows Vista";
        }
      #endif // Q_OS_WIN32
      break;
    }
  }
  m_systemStyleDescription = m_systemStyleName + " Style";
  QString systemStyleNameLower = m_systemStyleName.toLower();
  m_palettes.insert(systemStyleNameLower, &m_systemPallete);
  m_fontSets.insert(systemStyleNameLower, &m_systemFontSet);
  m_palettes.insert("system", &m_systemPallete);
  m_fontSets.insert("system", &m_systemFontSet);
  #ifdef Q_OS_WIN32
    QFont fixedFont("Courier", 9);
    m_fontSets.insert("cleanlooks", new QFontSet(QFont("Arial", 10)));
    m_fontSets.insert("motif",
                      new QFontSet(QFont("MS Reference Sans Serif", 9)));
    QFont plastiqueFont("Trebuchet MS", 10);
    plastiqueFont.setStyleStrategy(QFont::PreferAntialias);
    m_fontSets.insert("plastique", new QFontSet(plastiqueFont));
  #endif // Q_OS_WIN32
  #ifndef Q_OS_WIN32
    QFont fixedFont("Courier", 11);
    QFont windowsFont("Tahoma", 9);
    m_fontSets.insert("windows", new QFontSet(windowsFont));
  #endif // Q_OS_WIN32
  m_fontSets.insert("cde", new QFontSet(fixedFont));
  QApplication::setFont(fixedFont, "QTextArea");
  m_systemFontSet.setFixedFont(fixedFont);
  m_availableThemeNames = m_availableStyleNames;
  m_availableThemeNames.append("System");
  #ifdef Q_OS_WIN32
    if (m_winThemeable) {
      m_availableStyleNames.replace(m_availableStyleNames.indexOf("Windows"),
                                    "Windows Classic");
      if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) {
        if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
          m_availableStyleNames.removeAt(
                                   m_availableStyleNames.indexOf("WindowsXP"));
          m_availableStyleNames.replace(
               m_availableStyleNames.indexOf("WindowsVista"), "Windows Vista");
        } else {
          m_availableStyleNames.replace(
                     m_availableStyleNames.indexOf("WindowsXP"), "Windows XP");
        }
        m_availableThemeNames.replace(
                   m_availableThemeNames.indexOf("Windows"), "Windows Classic");
      }
    } else {
      if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) {
        m_availableStyleNames.removeAt(
                                      m_availableStyleNames.indexOf("Windows"));
        if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
          m_availableStyleNames.removeAt(
                                    m_availableStyleNames.indexOf("WindowsXP"));
          m_availableStyleNames.replace(
                      m_availableStyleNames.indexOf("WindowsVista"), "Windows");

        } else {
          m_availableStyleNames.replace(
                         m_availableStyleNames.indexOf("WindowsXP"), "Windows");
        }
      }
      m_availableThemeNames.removeAt(m_availableThemeNames.indexOf("Windows"));
    }
    if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) {
      m_availableThemeNames.removeAt(
                                   m_availableThemeNames.indexOf("WindowsXP"));
      if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
        m_availableThemeNames.removeAt(
                                m_availableThemeNames.indexOf("WindowsVista"));
      }
    }
  #endif // Q_OS_WIN32
}

// QStyleManager :: Private Destructor.  ---------------------------------------

QStyleManager::~QStyleManager()
{
  // disabled destructor
}

// QStyleManager :: Public Member Functions. -----------------------------------

/*!
 * \brief Returns system style name.
 *
 * \return system style name
 */
const QString &QStyleManager::systemStyleName() const
{
  return m_systemStyleName;
}

/*!
 * \brief Returns system style description.
 *
 * \return system style description
 */
const QString &QStyleManager::systemStyleDescription() const
{
  return m_systemStyleDescription;
}

/*!
 * \brief Returns available style names.
 *
 * \return available style names
 */
QStringList &QStyleManager::availableStyleNames()
{
  return m_availableStyleNames;
}

/*!
 * \brief Returns available theme names.
 *
 * \return available theme names
 */
QStringList &QStyleManager::availableThemeNames()
{
  return m_availableThemeNames;
}

/*!
 * \brief Sets the specified style.
 *
 * \param env the JNIEnv pointer 
 * \param name the style name 
 * 
 * \return \c true if succeed
 */
jboolean QStyleManager::setStyle(JNIEnv *env, jstring name)
{
  Q_ASSERT(env);
  Q_ASSERT(name);
  SWING_REENTRANT_RETURN(setStyle, bool, SWING_ENV_ARG, JSTRING_ARG(name))
  QStringAdapter styleName(env, name);
  QStyle *style = createStyle(styleName);
  if (style) {
    qAppAdapter->setStyle(style);
    if (m_useSystemTheme) {
      qAppAdapter->setFontSet(&m_systemFontSet);
      qAppAdapter->setPalette(m_systemPallete);
    }
    return true;
  }
  return false;
}

/*!
 * \brief Sets theme.
 *
 * \param env the JNIEnv pointer
 * \param colorPalette the color palette
 * \param fontSet the font set
 */
void QStyleManager::setTheme(JNIEnv *env, jobject colorPalette, jobject fontSet)
{
  Q_ASSERT(env);
  SWING_REENTRANT(setTheme, SWING_ENV_ARG, JOBJECT_ARG(colorPalette),
                  JOBJECT_ARG(fontSet))
  if (fontSet) {
    if (env->IsInstanceOf(fontSet, sm_systemFontSetClass)) {
      jstring fontSetName = (jstring)env->GetObjectField(fontSet,
                                                      sm_systemFontSetNameFID);
      qAppAdapter->setFontSet(getFontSet(QStringAdapter(env, fontSetName)));
    } else {
      QFontSet *qFontSet = getFontSet(env, fontSet);
      if (!qFontSet) {
        return;
      }
      qAppAdapter->setFontSet(qFontSet);
      delete qFontSet;
    }
  }
  if (colorPalette) {
    if (env->IsInstanceOf(colorPalette, sm_systemColorPaletteClass)) {
      jstring colorPaletteName = (jstring)env->GetObjectField(colorPalette,
                                                 sm_systemColorPaletteNameFID);
      qAppAdapter->setPalette(*getPalette(QStringAdapter(env,
                                                         colorPaletteName)));
    } else {
      QPalette palette;
      loadPalette(env, colorPalette, &palette);
      qAppAdapter->setPalette(palette);
    }
  }
}

/*!
 * \brief Sets whether or not using system theme.
 *
 * \param env the JNIEnv pointer 
 * \param useSystemTheme \c true if using system theme
 */
void QStyleManager::setUseSystemTheme(JNIEnv *env, jboolean useSystemTheme)
{
  Q_ASSERT(env);
  SWING_REENTRANT(setUseSystemTheme, SWING_ENV_ARG,
                  JBOOLEAN_ARG(useSystemTheme))
  if (!m_useSystemTheme) {
    qAppAdapter->setFontSet(&m_systemFontSet);
    qAppAdapter->setPalette(m_systemPallete);
  }
  m_useSystemTheme = useSystemTheme;
}

/*!
 * \brief Fills the specified color palette.
 *
 * \param env the JNIEnv pointer
 * \param customColorPalette the CustomColorPalette java object
 * \param name the color palette name
 */
void QStyleManager::fillPalette(JNIEnv *env, jobject customColorPalette,
                                jstring name)
{
  Q_ASSERT(env);
  Q_ASSERT(customColorPalette);
  Q_ASSERT(name);
  SWING_REENTRANT(fillPalette, SWING_ENV_ARG, JOBJECT_ARG(customColorPalette),
                  JSTRING_ARG(name))
  fillPalette(env, customColorPalette, getPalette(QStringAdapter(env, name)));
}

/*!
 * \brief Fills the palette using specified color.
 *
 * \param env the JNIEnv pointer
 * \param customColorPalette the ColorPalette java object
 * \param argb the argb value of the color
 */
void QStyleManager::fillPalette(JNIEnv *env, jobject customColorPalette,
                                jint argb)
{
  Q_ASSERT(env);
  Q_ASSERT(customColorPalette);
  SWING_REENTRANT(fillPalette, SWING_ENV_ARG, JOBJECT_ARG(customColorPalette),
                  JINT_ARG(argb))
  QColor buttonColor = QColorAdapter(argb);
  QPalette palette(buttonColor);
  fillPalette(env, customColorPalette, &palette);
}

/*!
 * \brief Fills the specified font set.
 *
 * \param env the JNIEnv pointer
 * \param customFontSet the CustomFontSet java object
 * \param name the font set name
 */
void QStyleManager::fillFontSet(JNIEnv *env, jobject customFontSet,
                                jstring name)
{
  Q_ASSERT(env);
  Q_ASSERT(customFontSet);
  Q_ASSERT(name);
  SWING_REENTRANT(fillFontSet, SWING_ENV_ARG, JOBJECT_ARG(customFontSet),
                  JSTRING_ARG(name))
  QFontSet *fontSet = getFontSet(QStringAdapter(env, name));
  if (!sm_defaultFontFID &&
      !initFontSetFIDs(env, env->GetObjectClass(customFontSet))) {
    FATAL_LOGGED_ERROR("CustomFontSet initialization failed");
  }
  if (!fillFont(env, customFontSet, sm_defaultFontFID,
                fontSet->defaultFont()) ||
      !fillFont(env, customFontSet, sm_componentFontFID,
                fontSet->componentFont()) ||
      !fillFont(env, customFontSet, sm_buttonFontFID, fontSet->buttonFont()) ||
      !fillFont(env, customFontSet, sm_menuFontFID, fontSet->menuFont()) ||
      !fillFont(env, customFontSet, sm_menuBarFontFID,
                fontSet->menuBarFont()) ||
      !fillFont(env, customFontSet, sm_textFontFID, fontSet->textFont()) ||
      !fillFont(env, customFontSet, sm_toolTipFontFID,
                fontSet->toolTipFont())) {
    JNIWrapper::throwRuntimeExcpetion(env, "Could not fill custom font set");
  }
}

// QStyleManager :: Public Static Member Function. -----------------------------

/*!
 * \brief Initializes QStyleManager class.
 *
 * \param env the JNIEnv pointer
 * \param systemColorPaletteClass the CustomColorPalette class
 * \param systemFontSetClass the CustomFontSet class
 */
void QStyleManager::initialize(JNIEnv *env, jclass systemColorPaletteClass,
                               jclass systemFontSetClass)
{
  Q_ASSERT(!sm_instance);
  sm_instance = new QStyleManager();
  if (!INIT_CLASS(systemColorPalette, systemColorPaletteClass) ||
      !INIT_CLASS(systemFontSet, systemFontSetClass) ||
      !INIT_NFID(systemColorPaletteName, systemColorPaletteClass, "name",
                 "Ljava/lang/String;") ||
      !INIT_NFID(systemFontSetName, systemFontSetClass, "name",
                 "Ljava/lang/String;")) {
    FATAL_LOGGED_ERROR("QStyleManager initialization failed");
  }
}

/*!
 * \brief Sets custom property.
 *
 * \param name the property name
 * \param value the property value
 */
void QStyleManager::setCustomProperty(const QString &name,
                                      const QString &value)
{
  bool trueValue = (value == QLatin1String("true"));
  if (name == QLatin1String("stylePatchEnabled")) {
    #ifdef Q_OS_WIN32
      QWindowsNativeStyle:: setPatchEnabled(trueValue);
    #endif // Q_OS_WIN32
    #ifndef Q_OS_WIN32
      Q_UNUSED(trueValue); // TODO: temp - waiting for other styles
    #endif // Q_OS_WIN32
  }
  #ifdef Q_OS_WIN32
    if (name == QLatin1String("explorerStyleEnabled")) {
      QWindowsNativeStyle::setExplorerStyleEnabled(trueValue);
    }
  #endif // Q_OS_WIN32
}

// QStyleManager :: Private Member Functions. ----------------------------------

QStyle *QStyleManager::createStyle(const QString &styleName)
{
  QStyle *style = 0;
  QString styleNameLower = styleName.toLower();
  if (styleNameLower == qAppAdapter->style()->objectName()) {
    return qAppAdapter->style();
  #ifndef Q_OS_WIN32
  } else if (styleNameLower == "windows") {
    style = new QWindowsClassicStyle();
    style->setObjectName("windows");
  #endif // Q_OS_WIN32
  #ifdef Q_OS_WIN32
  } else if ((styleNameLower == "windows classic") ||
             (styleNameLower == "windows")) {
    if (m_winThemeable) {
      style = new QWindowsClassicStyle();
      style->setObjectName("windows classic");
    } else {
      style = new QWindowsNativeStyle();
      style->setObjectName("windows");
    }
  } else if ((styleNameLower == "windows xp") ||
             (styleNameLower == "windowsxp")) {
    style = new QWindowsNativeStyle();
    style->setObjectName("windowsxp");
  } else if ((styleNameLower == "windows vista") ||
             (styleNameLower == "windowsvista")) {
    style = new QWindowsNativeStyle();
    style->setObjectName("windowsvista");
  #endif // Q_OS_WIN32
  } else {
    style = QStyleFactory::create(styleName);
  }
  return style;
}

QPalette *QStyleManager::getPalette(const QString &paletteName)
{
  QString paletteNameLower = paletteName.toLower();
  QPalette *palette = m_palettes.value(paletteNameLower);
  if (!palette) {
    QStyle *style = createStyle(paletteNameLower);
    if (style) {
      palette = new QPalette(style->standardPalette());
      if (style != qAppAdapter->style()) {
        delete style;
      }
      m_palettes.insert(paletteNameLower, palette);
    } else {
      palette = &m_systemPallete;
    }
  }
  return palette;
}

QFontSet *QStyleManager::getFontSet(const QString &fontSetName)
{
  QFontSet *fontSet = m_fontSets.value(fontSetName.toLower());
  if (!fontSet) {
    fontSet = &m_systemFontSet;
  }
  return fontSet;
}

QFontSet *QStyleManager::getFontSet(JNIEnv *env, jobject fontSet)
{
  if (!sm_getDefaultFontMID &&
      !initFontSetMIDs(env, env->GetSuperclass(sm_systemFontSetClass))) {
    FATAL_LOGGED_ERROR("FontSet initialization failed");
  }
  QFont font;
  if (!getFont(env, font, fontSet, sm_getDefaultFontMID)) {
    return 0;
  }
  QFontSet *qFontSet = new QFontSet(font);
  if (!getFont(env, font, fontSet, sm_getFixedFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setFixedFont(font);
  if (!getFont(env, font, fontSet, sm_getComponentFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setComponentFont(font);
  if (!getFont(env, font, fontSet, sm_getButtonFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setButtonFont(font);
  if (!getFont(env, font, fontSet, sm_getMenuFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setMenuFont(font);
  if (!getFont(env, font, fontSet, sm_getMenuBarFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setMenuBarFont(font);
  if (!getFont(env, font, fontSet, sm_getTextFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setTextFont(font);
  if (!getFont(env, font, fontSet, sm_getToolTipFontMID)) {
    delete qFontSet;
    return 0;
  }
  qFontSet->setToolTipFont(font);
  return qFontSet;
}

void QStyleManager::fillPalette(JNIEnv *env, jobject customColorPalette,
                                QPalette *palette)
{
  if (!sm_activeBackgroundColorFID &&
      !initColorPaletteFIDs(env, env->GetObjectClass(customColorPalette))) {
    FATAL_LOGGED_ERROR("CustomColorPalette initialization failed");
  }
  if (!fillColor(env, customColorPalette, sm_activeBackgroundColorFID,
                 palette->color(QPalette::Active, QPalette::Background)) ||
      !fillColor(env, customColorPalette, sm_inactiveBackgroundColorFID,
                 palette->color(QPalette::Inactive, QPalette::Background)) ||
      !fillColor(env, customColorPalette, sm_disabledBackgroundColorFID,
                 palette->color(QPalette::Disabled, QPalette::Background)) ||
      !fillColor(env, customColorPalette, sm_activeForegroundColorFID,
                 palette->color(QPalette::Active, QPalette::Foreground)) ||
      !fillColor(env, customColorPalette, sm_inactiveForegroundColorFID,
                 palette->color(QPalette::Inactive, QPalette::Foreground)) ||
      !fillColor(env, customColorPalette, sm_disabledForegroundColorFID,
                 palette->color(QPalette::Disabled, QPalette::Foreground)) ||
      !fillColor(env, customColorPalette, sm_activeBaseColorFID,
                 palette->color(QPalette::Active, QPalette::Base)) ||
      !fillColor(env, customColorPalette, sm_inactiveBaseColorFID,
                 palette->color(QPalette::Inactive, QPalette::Base)) ||
      !fillColor(env, customColorPalette, sm_disabledBaseColorFID,
                 palette->color(QPalette::Disabled, QPalette::Base)) ||
      !fillColor(env, customColorPalette, sm_activeAlternateBaseColorFID,
                 palette->color(QPalette::Active, QPalette::AlternateBase)) ||
      !fillColor(env, customColorPalette, sm_inactiveAlternateBaseColorFID,
                 palette->color(QPalette::Inactive, QPalette::AlternateBase)) ||
      !fillColor(env, customColorPalette, sm_disabledAlternateBaseColorFID,
                 palette->color(QPalette::Disabled, QPalette::AlternateBase)) ||
      !fillColor(env, customColorPalette, sm_activeTextColorFID,
                 palette->color(QPalette::Active, QPalette::Text)) ||
      !fillColor(env, customColorPalette, sm_inactiveTextColorFID,
                 palette->color(QPalette::Inactive, QPalette::Text)) ||
      !fillColor(env, customColorPalette, sm_disabledTextColorFID,
                 palette->color(QPalette::Disabled, QPalette::Text)) ||
      !fillColor(env, customColorPalette, sm_activeButtonColorFID,
                 palette->color(QPalette::Active, QPalette::Button)) ||
      !fillColor(env, customColorPalette, sm_inactiveButtonColorFID,
                 palette->color(QPalette::Inactive, QPalette::Button)) ||
      !fillColor(env, customColorPalette, sm_disabledButtonColorFID,
                 palette->color(QPalette::Disabled, QPalette::Button)) ||
      !fillColor(env, customColorPalette, sm_activeButtonTextColorFID,
                 palette->color(QPalette::Active, QPalette::ButtonText)) ||
      !fillColor(env, customColorPalette, sm_inactiveButtonTextColorFID,
                 palette->color(QPalette::Inactive, QPalette::ButtonText)) ||
      !fillColor(env, customColorPalette, sm_disabledButtonTextColorFID,
                 palette->color(QPalette::Disabled, QPalette::ButtonText)) ||
      !fillColor(env, customColorPalette, sm_activeBrightTextColorFID,
                 palette->color(QPalette::Active, QPalette::BrightText)) ||
      !fillColor(env, customColorPalette, sm_inactiveBrightTextColorFID,
                 palette->color(QPalette::Inactive, QPalette::BrightText)) ||
      !fillColor(env, customColorPalette, sm_disabledBrightTextColorFID,
                 palette->color(QPalette::Disabled, QPalette::BrightText)) ||
      !fillColor(env, customColorPalette, sm_activeLightColorFID,
                 palette->color(QPalette::Active, QPalette::Light)) ||
      !fillColor(env, customColorPalette, sm_inactiveLightColorFID,
                 palette->color(QPalette::Inactive, QPalette::Light)) ||
      !fillColor(env, customColorPalette, sm_disabledLightColorFID,
                 palette->color(QPalette::Disabled, QPalette::Light)) ||
      !fillColor(env, customColorPalette, sm_activeMidlightColorFID,
                 palette->color(QPalette::Active, QPalette::Midlight)) ||
      !fillColor(env, customColorPalette, sm_inactiveMidlightColorFID,
                 palette->color(QPalette::Inactive, QPalette::Midlight)) ||
      !fillColor(env, customColorPalette, sm_disabledMidlightColorFID,
                 palette->color(QPalette::Disabled, QPalette::Midlight)) ||
      !fillColor(env, customColorPalette, sm_activeDarkColorFID,
                 palette->color(QPalette::Active, QPalette::Dark)) ||
      !fillColor(env, customColorPalette, sm_inactiveDarkColorFID,
                 palette->color(QPalette::Inactive, QPalette::Dark)) ||
      !fillColor(env, customColorPalette, sm_disabledDarkColorFID,
                 palette->color(QPalette::Disabled, QPalette::Dark)) ||
      !fillColor(env, customColorPalette, sm_activeMidColorFID,
                 palette->color(QPalette::Active, QPalette::Mid)) ||
      !fillColor(env, customColorPalette, sm_inactiveMidColorFID,
                 palette->color(QPalette::Inactive, QPalette::Mid)) ||
      !fillColor(env, customColorPalette, sm_disabledMidColorFID,
                 palette->color(QPalette::Disabled, QPalette::Mid)) ||
      !fillColor(env, customColorPalette, sm_activeShadowColorFID,
                 palette->color(QPalette::Active, QPalette::Shadow)) ||
      !fillColor(env, customColorPalette, sm_inactiveShadowColorFID,
                 palette->color(QPalette::Inactive, QPalette::Shadow)) ||
      !fillColor(env, customColorPalette, sm_disabledShadowColorFID,
                 palette->color(QPalette::Disabled, QPalette::Shadow)) ||
      !fillColor(env, customColorPalette, sm_activeHighlightColorFID,
                 palette->color(QPalette::Active, QPalette::Highlight)) ||
      !fillColor(env, customColorPalette, sm_inactiveHighlightColorFID,
                 palette->color(QPalette::Inactive, QPalette::Highlight)) ||
      !fillColor(env, customColorPalette, sm_disabledHighlightColorFID,
                 palette->color(QPalette::Disabled, QPalette::Highlight)) ||
      !fillColor(env, customColorPalette, sm_activeHighlightedTextColorFID,
                 palette->color(QPalette::Active, QPalette::HighlightedText)) ||
      !fillColor(env, customColorPalette, sm_inactiveHighlightedTextColorFID,
                 palette->color(QPalette::Inactive,
                 QPalette::HighlightedText)) ||
      !fillColor(env, customColorPalette, sm_disabledHighlightedTextColorFID,
                 palette->color(QPalette::Disabled,
                 QPalette::HighlightedText)) ||
      !fillColor(env, customColorPalette, sm_activeLinkColorFID,
                 palette->color(QPalette::Active, QPalette::Link)) ||
      !fillColor(env, customColorPalette, sm_inactiveLinkColorFID,
                 palette->color(QPalette::Inactive, QPalette::Link)) ||
      !fillColor(env, customColorPalette, sm_disabledLinkColorFID,
                 palette->color(QPalette::Disabled, QPalette::Link)) ||
      !fillColor(env, customColorPalette, sm_activeLinkVisitedColorFID,
                 palette->color(QPalette::Active, QPalette::LinkVisited)) ||
      !fillColor(env, customColorPalette, sm_inactiveLinkVisitedColorFID,
                 palette->color(QPalette::Inactive, QPalette::LinkVisited)) ||
      !fillColor(env, customColorPalette, sm_disabledLinkVisitedColorFID,
                 palette->color(QPalette::Disabled, QPalette::LinkVisited))) {
    JNIWrapper::throwRuntimeExcpetion(env,
                                      "Could not fill custom color palette");
  }
}

bool QStyleManager::fillColor(JNIEnv *env, jobject customColorPalette,
                              jfieldID fid, QColor color)
{
  if (color.isValid()) {
    jobject jcolor = QColorAdapter::toJColor(color);
    if (!jcolor) {
      return false; // out of memory
    }
    env->SetObjectField(customColorPalette, fid, jcolor);
  } else {
    env->SetObjectField(customColorPalette, fid, 0);
  }
  return true;
}

void QStyleManager::loadPalette(JNIEnv *env, jobject colorPalette,
                                QPalette *palette)
{
  if (!sm_getActiveBackgroundColorMID &&
      !initColorPaletteMIDs(env,
                            env->GetSuperclass(sm_systemColorPaletteClass))) {
    FATAL_LOGGED_ERROR("CustomColorPalette initialization failed");
  }
  loadColor(env, colorPalette, sm_getActiveBackgroundColorMID, palette,
            QPalette::Active, QPalette::Background);
  loadColor(env, colorPalette, sm_getInactiveBackgroundColorMID, palette,
            QPalette::Inactive, QPalette::Background);
  loadColor(env, colorPalette, sm_getDisabledBackgroundColorMID, palette,
            QPalette::Disabled, QPalette::Background);
  loadColor(env, colorPalette, sm_getActiveForegroundColorMID, palette,
            QPalette::Active, QPalette::Foreground);
  loadColor(env, colorPalette, sm_getInactiveForegroundColorMID, palette,
            QPalette::Inactive, QPalette::Foreground);
  loadColor(env, colorPalette, sm_getDisabledForegroundColorMID, palette,
            QPalette::Disabled, QPalette::Foreground);
  loadColor(env, colorPalette, sm_getActiveBaseColorMID, palette,
            QPalette::Active, QPalette::Base);
  loadColor(env, colorPalette, sm_getInactiveBaseColorMID, palette,
            QPalette::Inactive, QPalette::Base);
  loadColor(env, colorPalette, sm_getDisabledBaseColorMID, palette,
            QPalette::Disabled, QPalette::Base);
  loadColor(env, colorPalette, sm_getActiveAlternateBaseColorMID, palette,
            QPalette::Active, QPalette::AlternateBase);
  loadColor(env, colorPalette, sm_getInactiveAlternateBaseColorMID, palette,
            QPalette::Inactive, QPalette::AlternateBase);
  loadColor(env, colorPalette, sm_getDisabledAlternateBaseColorMID, palette,
            QPalette::Disabled, QPalette::AlternateBase);
  loadColor(env, colorPalette, sm_getActiveTextColorMID, palette,
            QPalette::Active, QPalette::Text);
  loadColor(env, colorPalette, sm_getInactiveTextColorMID, palette,
            QPalette::Inactive, QPalette::Text);
  loadColor(env, colorPalette, sm_getDisabledTextColorMID, palette,
            QPalette::Disabled, QPalette::Text);
  loadColor(env, colorPalette, sm_getActiveButtonColorMID, palette,
            QPalette::Active, QPalette::Button);
  loadColor(env, colorPalette, sm_getInactiveButtonColorMID, palette,
            QPalette::Inactive, QPalette::Button);
  loadColor(env, colorPalette, sm_getDisabledButtonColorMID, palette,
            QPalette::Disabled, QPalette::Button);
  loadColor(env, colorPalette, sm_getActiveButtonTextColorMID, palette,
            QPalette::Active, QPalette::ButtonText);
  loadColor(env, colorPalette, sm_getInactiveButtonTextColorMID, palette,
            QPalette::Inactive, QPalette::ButtonText);
  loadColor(env, colorPalette, sm_getDisabledButtonTextColorMID, palette,
            QPalette::Disabled, QPalette::ButtonText);
  loadColor(env, colorPalette, sm_getActiveBrightTextColorMID, palette,
            QPalette::Active, QPalette::BrightText);
  loadColor(env, colorPalette, sm_getInactiveBrightTextColorMID, palette,
            QPalette::Inactive, QPalette::BrightText);
  loadColor(env, colorPalette, sm_getDisabledBrightTextColorMID, palette,
            QPalette::Disabled, QPalette::BrightText);
  loadColor(env, colorPalette, sm_getActiveLightColorMID, palette,
            QPalette::Active, QPalette::Light);
  loadColor(env, colorPalette, sm_getInactiveLightColorMID, palette,
            QPalette::Inactive, QPalette::Light);
  loadColor(env, colorPalette, sm_getDisabledLightColorMID, palette,
            QPalette::Disabled, QPalette::Light);
  loadColor(env, colorPalette, sm_getActiveMidlightColorMID, palette,
            QPalette::Active, QPalette::Midlight);
  loadColor(env, colorPalette, sm_getInactiveMidlightColorMID, palette,
            QPalette::Inactive, QPalette::Midlight);
  loadColor(env, colorPalette, sm_getDisabledMidlightColorMID, palette,
            QPalette::Disabled, QPalette::Midlight);
  loadColor(env, colorPalette, sm_getActiveDarkColorMID, palette,
            QPalette::Active, QPalette::Dark);
  loadColor(env, colorPalette, sm_getInactiveDarkColorMID, palette,
            QPalette::Inactive, QPalette::Dark);
  loadColor(env, colorPalette, sm_getDisabledDarkColorMID, palette,
            QPalette::Disabled, QPalette::Dark);
  loadColor(env, colorPalette, sm_getActiveMidColorMID, palette,
            QPalette::Active, QPalette::Mid);
  loadColor(env, colorPalette, sm_getInactiveMidColorMID, palette,
            QPalette::Inactive, QPalette::Mid);
  loadColor(env, colorPalette, sm_getDisabledMidColorMID, palette,
            QPalette::Disabled, QPalette::Mid);
  loadColor(env, colorPalette, sm_getActiveShadowColorMID, palette,
            QPalette::Active, QPalette::Shadow);
  loadColor(env, colorPalette, sm_getInactiveShadowColorMID, palette,
            QPalette::Inactive, QPalette::Shadow);
  loadColor(env, colorPalette, sm_getDisabledShadowColorMID, palette,
            QPalette::Disabled, QPalette::Shadow);
  loadColor(env, colorPalette, sm_getActiveHighlightColorMID, palette,
            QPalette::Active, QPalette::Highlight);
  loadColor(env, colorPalette, sm_getInactiveHighlightColorMID, palette,
            QPalette::Inactive, QPalette::Highlight);
  loadColor(env, colorPalette, sm_getDisabledHighlightColorMID, palette,
            QPalette::Disabled, QPalette::Highlight);
  loadColor(env, colorPalette, sm_getActiveHighlightedTextColorMID, palette,
            QPalette::Active, QPalette::HighlightedText);
  loadColor(env, colorPalette, sm_getInactiveHighlightedTextColorMID, palette,
            QPalette::Inactive, QPalette::HighlightedText);
  loadColor(env, colorPalette, sm_getDisabledHighlightedTextColorMID, palette,
            QPalette::Disabled, QPalette::HighlightedText);
  loadColor(env, colorPalette, sm_getActiveLinkColorMID, palette,
            QPalette::Active, QPalette::Link);
  loadColor(env, colorPalette, sm_getInactiveLinkColorMID, palette,
            QPalette::Inactive, QPalette::Link);
  loadColor(env, colorPalette, sm_getDisabledLinkColorMID, palette,
            QPalette::Disabled, QPalette::Link);
  loadColor(env, colorPalette, sm_getActiveLinkVisitedColorMID, palette,
            QPalette::Active, QPalette::LinkVisited);
  loadColor(env, colorPalette, sm_getInactiveLinkVisitedColorMID, palette,
            QPalette::Inactive, QPalette::LinkVisited);
  loadColor(env, colorPalette, sm_getDisabledLinkVisitedColorMID, palette,
            QPalette::Disabled, QPalette::LinkVisited);
}

void QStyleManager::loadColor(JNIEnv *env, jobject customColorPalette,
                              jmethodID metodID, QPalette *palette,
                              QPalette::ColorGroup cg, QPalette::ColorRole cr)
{
  jobject jcolor = 0;
  if (JNIWrapper::callObjectMethod(env, jcolor, customColorPalette, metodID)) {
    if (jcolor) {
      palette->setColor(cg, cr, QColorAdapter(jcolor));
    }
  }
}

bool QStyleManager::fillFont(JNIEnv *env, jobject customFontSet, jfieldID fid,
                             QFont font)
{
  jobject jfont = QFontAdapter::toJFont(font);
  if (jfont) {
    env->SetObjectField(customFontSet, fid, jfont);
    return true;
  }
  return false; // out of memory
}

bool QStyleManager::getFont(JNIEnv *env, QFont &result, jobject fontSet,
                            jmethodID mid)
{
  jobject font = env->CallObjectMethod(fontSet, mid);
  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    return false;
  }
  if (font) {
    result = *QFontAdapter::toQFont(font);
  } else {
    result = QFont();
  }
  return true;

}

bool QStyleManager::initColorPaletteFIDs(JNIEnv *env, jclass cls)
{
  const char *sig = "Lcom/cute4j/swing/graphics/Color;";
  return (INIT_FID(activeBackgroundColor, cls, sig) &&
          INIT_FID(inactiveBackgroundColor, cls, sig) &&
          INIT_FID(disabledBackgroundColor, cls, sig) &&
          INIT_FID(activeForegroundColor, cls, sig) &&
          INIT_FID(inactiveForegroundColor, cls, sig) &&
          INIT_FID(disabledForegroundColor, cls, sig) &&
          INIT_FID(activeBaseColor, cls, sig) &&
          INIT_FID(inactiveBaseColor, cls, sig) &&
          INIT_FID(disabledBaseColor, cls, sig) &&
          INIT_FID(activeAlternateBaseColor, cls, sig) &&
          INIT_FID(inactiveAlternateBaseColor, cls, sig) &&
          INIT_FID(disabledAlternateBaseColor, cls, sig) &&
          INIT_FID(activeTextColor, cls, sig) &&
          INIT_FID(inactiveTextColor, cls, sig) &&
          INIT_FID(disabledTextColor, cls, sig) &&
          INIT_FID(activeButtonColor, cls, sig) &&
          INIT_FID(inactiveButtonColor, cls, sig) &&
          INIT_FID(disabledButtonColor, cls, sig) &&
          INIT_FID(activeButtonTextColor, cls, sig) &&
          INIT_FID(inactiveButtonTextColor, cls, sig) &&
          INIT_FID(disabledButtonTextColor, cls, sig) &&
          INIT_FID(activeBrightTextColor, cls, sig) &&
          INIT_FID(inactiveBrightTextColor, cls, sig) &&
          INIT_FID(disabledBrightTextColor, cls, sig) &&
          INIT_FID(activeLightColor, cls, sig) &&
          INIT_FID(inactiveLightColor, cls, sig) &&
          INIT_FID(disabledLightColor, cls, sig) &&
          INIT_FID(activeMidlightColor, cls, sig) &&
          INIT_FID(inactiveMidlightColor, cls, sig) &&
          INIT_FID(disabledMidlightColor, cls, sig) &&
          INIT_FID(activeDarkColor, cls, sig) &&
          INIT_FID(inactiveDarkColor, cls, sig) &&
          INIT_FID(disabledDarkColor, cls, sig) &&
          INIT_FID(activeMidColor, cls, sig) &&
          INIT_FID(inactiveMidColor, cls, sig) &&
          INIT_FID(disabledMidColor, cls, sig) &&
          INIT_FID(activeShadowColor, cls, sig) &&
          INIT_FID(inactiveShadowColor, cls, sig) &&
          INIT_FID(disabledShadowColor, cls, sig) &&
          INIT_FID(activeHighlightColor, cls, sig) &&
          INIT_FID(inactiveHighlightColor, cls, sig) &&
          INIT_FID(disabledHighlightColor, cls, sig) &&
          INIT_FID(activeHighlightedTextColor, cls, sig) &&
          INIT_FID(inactiveHighlightedTextColor, cls, sig) &&
          INIT_FID(disabledHighlightedTextColor, cls, sig) &&
          INIT_FID(activeLinkColor, cls, sig) &&
          INIT_FID(inactiveLinkColor, cls, sig) &&
          INIT_FID(disabledLinkColor, cls, sig) &&
          INIT_FID(activeLinkVisitedColor, cls, sig) &&
          INIT_FID(inactiveLinkVisitedColor, cls, sig) &&
          INIT_FID(disabledLinkVisitedColor, cls, sig));
}

bool QStyleManager::initColorPaletteMIDs(JNIEnv *env, jclass cls)
{
  const char *sig = "()Lcom/cute4j/swing/graphics/Color;";
  return (INIT_MID(getActiveBackgroundColor, cls, sig) &&
          INIT_MID(getInactiveBackgroundColor, cls, sig) &&
          INIT_MID(getDisabledBackgroundColor, cls, sig) &&
          INIT_MID(getActiveForegroundColor, cls, sig) &&
          INIT_MID(getInactiveForegroundColor, cls, sig) &&
          INIT_MID(getDisabledForegroundColor, cls, sig) &&
          INIT_MID(getActiveBaseColor, cls, sig) &&
          INIT_MID(getInactiveBaseColor, cls, sig) &&
          INIT_MID(getDisabledBaseColor, cls, sig) &&
          INIT_MID(getActiveAlternateBaseColor, cls, sig) &&
          INIT_MID(getInactiveAlternateBaseColor, cls, sig) &&
          INIT_MID(getDisabledAlternateBaseColor, cls, sig) &&
          INIT_MID(getActiveTextColor, cls, sig) &&
          INIT_MID(getInactiveTextColor, cls, sig) &&
          INIT_MID(getDisabledTextColor, cls, sig) &&
          INIT_MID(getActiveButtonColor, cls, sig) &&
          INIT_MID(getInactiveButtonColor, cls, sig) &&
          INIT_MID(getDisabledButtonColor, cls, sig) &&
          INIT_MID(getActiveButtonTextColor, cls, sig) &&
          INIT_MID(getInactiveButtonTextColor, cls, sig) &&
          INIT_MID(getDisabledButtonTextColor, cls, sig) &&
          INIT_MID(getActiveBrightTextColor, cls, sig) &&
          INIT_MID(getInactiveBrightTextColor, cls, sig) &&
          INIT_MID(getDisabledBrightTextColor, cls, sig) &&
          INIT_MID(getActiveLightColor, cls, sig) &&
          INIT_MID(getInactiveLightColor, cls, sig) &&
          INIT_MID(getDisabledLightColor, cls, sig) &&
          INIT_MID(getActiveMidlightColor, cls, sig) &&
          INIT_MID(getInactiveMidlightColor, cls, sig) &&
          INIT_MID(getDisabledMidlightColor, cls, sig) &&
          INIT_MID(getActiveDarkColor, cls, sig) &&
          INIT_MID(getInactiveDarkColor, cls, sig) &&
          INIT_MID(getDisabledDarkColor, cls, sig) &&
          INIT_MID(getActiveMidColor, cls, sig) &&
          INIT_MID(getInactiveMidColor, cls, sig) &&
          INIT_MID(getDisabledMidColor, cls, sig) &&
          INIT_MID(getActiveShadowColor, cls, sig) &&
          INIT_MID(getInactiveShadowColor, cls, sig) &&
          INIT_MID(getDisabledShadowColor, cls, sig) &&
          INIT_MID(getActiveHighlightColor, cls, sig) &&
          INIT_MID(getInactiveHighlightColor, cls, sig) &&
          INIT_MID(getDisabledHighlightColor, cls, sig) &&
          INIT_MID(getActiveHighlightedTextColor, cls, sig) &&
          INIT_MID(getInactiveHighlightedTextColor, cls, sig) &&
          INIT_MID(getDisabledHighlightedTextColor, cls, sig) &&
          INIT_MID(getActiveLinkColor, cls, sig) &&
          INIT_MID(getInactiveLinkColor, cls, sig) &&
          INIT_MID(getDisabledLinkColor, cls, sig) &&
          INIT_MID(getActiveLinkVisitedColor, cls, sig) &&
          INIT_MID(getInactiveLinkVisitedColor, cls, sig) &&
          INIT_MID(getDisabledLinkVisitedColor, cls, sig));
}

bool QStyleManager::initFontSetFIDs(JNIEnv *env, jclass cls)
{
  const char *sig = "Lcom/cute4j/swing/graphics/Font;";
  return (INIT_FID(defaultFont, cls, sig) &&
          INIT_FID(componentFont, cls, sig) &&
          INIT_FID(buttonFont, cls, sig) &&
          INIT_FID(menuFont, cls, sig) &&
          INIT_FID(menuBarFont, cls, sig) &&
          INIT_FID(textFont, cls, sig) &&
          INIT_FID(toolTipFont, cls, sig));
}

bool QStyleManager::initFontSetMIDs(JNIEnv *env, jclass cls)
{
  const char *sig = "()Lcom/cute4j/swing/graphics/Font;";
  return (INIT_MID(getDefaultFont, cls, sig) &&
          INIT_MID(getFixedFont, cls, sig) &&
          INIT_MID(getComponentFont, cls, sig) &&
          INIT_MID(getButtonFont, cls, sig) &&
          INIT_MID(getMenuFont, cls, sig) &&
          INIT_MID(getMenuBarFont, cls, sig) &&
          INIT_MID(getTextFont, cls, sig) &&
          INIT_MID(getToolTipFont, cls, sig));
}

// QStyleManager :: Private Static Data Members. -------------------------------

QStyleManager *QStyleManager::sm_instance = 0;
jclass QStyleManager::sm_systemColorPaletteClass = 0;
jclass QStyleManager::sm_systemFontSetClass = 0;
jfieldID QStyleManager::sm_systemColorPaletteNameFID = 0;
jfieldID QStyleManager::sm_systemFontSetNameFID = 0;
jfieldID QStyleManager::sm_activeBackgroundColorFID = 0;
jfieldID QStyleManager::sm_inactiveBackgroundColorFID = 0;
jfieldID QStyleManager::sm_disabledBackgroundColorFID = 0;
jfieldID QStyleManager::sm_activeForegroundColorFID = 0;
jfieldID QStyleManager::sm_inactiveForegroundColorFID = 0;
jfieldID QStyleManager::sm_disabledForegroundColorFID = 0;
jfieldID QStyleManager::sm_activeBaseColorFID = 0;
jfieldID QStyleManager::sm_inactiveBaseColorFID = 0;
jfieldID QStyleManager::sm_disabledBaseColorFID = 0;
jfieldID QStyleManager::sm_activeAlternateBaseColorFID = 0;
jfieldID QStyleManager::sm_inactiveAlternateBaseColorFID = 0;
jfieldID QStyleManager::sm_disabledAlternateBaseColorFID = 0;
jfieldID QStyleManager::sm_activeTextColorFID = 0;
jfieldID QStyleManager::sm_inactiveTextColorFID = 0;
jfieldID QStyleManager::sm_disabledTextColorFID = 0;
jfieldID QStyleManager::sm_activeButtonColorFID = 0;
jfieldID QStyleManager::sm_inactiveButtonColorFID = 0;
jfieldID QStyleManager::sm_disabledButtonColorFID = 0;
jfieldID QStyleManager::sm_activeButtonTextColorFID = 0;
jfieldID QStyleManager::sm_inactiveButtonTextColorFID = 0;
jfieldID QStyleManager::sm_disabledButtonTextColorFID = 0;
jfieldID QStyleManager::sm_activeBrightTextColorFID = 0;
jfieldID QStyleManager::sm_inactiveBrightTextColorFID = 0;
jfieldID QStyleManager::sm_disabledBrightTextColorFID = 0;
jfieldID QStyleManager::sm_activeLightColorFID = 0;
jfieldID QStyleManager::sm_inactiveLightColorFID = 0;
jfieldID QStyleManager::sm_disabledLightColorFID = 0;
jfieldID QStyleManager::sm_activeMidlightColorFID = 0;
jfieldID QStyleManager::sm_inactiveMidlightColorFID = 0;
jfieldID QStyleManager::sm_disabledMidlightColorFID = 0;
jfieldID QStyleManager::sm_activeDarkColorFID = 0;
jfieldID QStyleManager::sm_inactiveDarkColorFID = 0;
jfieldID QStyleManager::sm_disabledDarkColorFID = 0;
jfieldID QStyleManager::sm_activeMidColorFID = 0;
jfieldID QStyleManager::sm_inactiveMidColorFID = 0;
jfieldID QStyleManager::sm_disabledMidColorFID = 0;
jfieldID QStyleManager::sm_activeShadowColorFID = 0;
jfieldID QStyleManager::sm_inactiveShadowColorFID = 0;
jfieldID QStyleManager::sm_disabledShadowColorFID = 0;
jfieldID QStyleManager::sm_activeHighlightColorFID = 0;
jfieldID QStyleManager::sm_inactiveHighlightColorFID = 0;
jfieldID QStyleManager::sm_disabledHighlightColorFID = 0;
jfieldID QStyleManager::sm_activeHighlightedTextColorFID = 0;
jfieldID QStyleManager::sm_inactiveHighlightedTextColorFID = 0;
jfieldID QStyleManager::sm_disabledHighlightedTextColorFID = 0;
jfieldID QStyleManager::sm_activeLinkColorFID = 0;
jfieldID QStyleManager::sm_inactiveLinkColorFID = 0;
jfieldID QStyleManager::sm_disabledLinkColorFID = 0;
jfieldID QStyleManager::sm_activeLinkVisitedColorFID = 0;
jfieldID QStyleManager::sm_inactiveLinkVisitedColorFID = 0;
jfieldID QStyleManager::sm_disabledLinkVisitedColorFID = 0;
jfieldID QStyleManager::sm_defaultFontFID = 0;
jfieldID QStyleManager::sm_componentFontFID = 0;
jfieldID QStyleManager::sm_buttonFontFID = 0;
jfieldID QStyleManager::sm_menuFontFID = 0;
jfieldID QStyleManager::sm_menuBarFontFID = 0;
jfieldID QStyleManager::sm_textFontFID = 0;
jfieldID QStyleManager::sm_toolTipFontFID = 0;
jmethodID QStyleManager::sm_getActiveBackgroundColorMID = 0;
jmethodID QStyleManager::sm_getInactiveBackgroundColorMID = 0;
jmethodID QStyleManager::sm_getDisabledBackgroundColorMID = 0;
jmethodID QStyleManager::sm_getActiveForegroundColorMID = 0;
jmethodID QStyleManager::sm_getInactiveForegroundColorMID = 0;
jmethodID QStyleManager::sm_getDisabledForegroundColorMID = 0;
jmethodID QStyleManager::sm_getActiveBaseColorMID = 0;
jmethodID QStyleManager::sm_getInactiveBaseColorMID = 0;
jmethodID QStyleManager::sm_getDisabledBaseColorMID = 0;
jmethodID QStyleManager::sm_getActiveAlternateBaseColorMID = 0;
jmethodID QStyleManager::sm_getInactiveAlternateBaseColorMID = 0;
jmethodID QStyleManager::sm_getDisabledAlternateBaseColorMID = 0;
jmethodID QStyleManager::sm_getActiveTextColorMID = 0;
jmethodID QStyleManager::sm_getInactiveTextColorMID = 0;
jmethodID QStyleManager::sm_getDisabledTextColorMID = 0;
jmethodID QStyleManager::sm_getActiveButtonColorMID = 0;
jmethodID QStyleManager::sm_getInactiveButtonColorMID = 0;
jmethodID QStyleManager::sm_getDisabledButtonColorMID = 0;
jmethodID QStyleManager::sm_getActiveButtonTextColorMID = 0;
jmethodID QStyleManager::sm_getInactiveButtonTextColorMID = 0;
jmethodID QStyleManager::sm_getDisabledButtonTextColorMID = 0;
jmethodID QStyleManager::sm_getActiveBrightTextColorMID = 0;
jmethodID QStyleManager::sm_getInactiveBrightTextColorMID = 0;
jmethodID QStyleManager::sm_getDisabledBrightTextColorMID = 0;
jmethodID QStyleManager::sm_getActiveLightColorMID = 0;
jmethodID QStyleManager::sm_getInactiveLightColorMID = 0;
jmethodID QStyleManager::sm_getDisabledLightColorMID = 0;
jmethodID QStyleManager::sm_getActiveMidlightColorMID = 0;
jmethodID QStyleManager::sm_getInactiveMidlightColorMID = 0;
jmethodID QStyleManager::sm_getDisabledMidlightColorMID = 0;
jmethodID QStyleManager::sm_getActiveDarkColorMID = 0;
jmethodID QStyleManager::sm_getInactiveDarkColorMID = 0;
jmethodID QStyleManager::sm_getDisabledDarkColorMID = 0;
jmethodID QStyleManager::sm_getActiveMidColorMID = 0;
jmethodID QStyleManager::sm_getInactiveMidColorMID = 0;
jmethodID QStyleManager::sm_getDisabledMidColorMID = 0;
jmethodID QStyleManager::sm_getActiveShadowColorMID = 0;
jmethodID QStyleManager::sm_getInactiveShadowColorMID = 0;
jmethodID QStyleManager::sm_getDisabledShadowColorMID = 0;
jmethodID QStyleManager::sm_getActiveHighlightColorMID = 0;
jmethodID QStyleManager::sm_getInactiveHighlightColorMID = 0;
jmethodID QStyleManager::sm_getDisabledHighlightColorMID = 0;
jmethodID QStyleManager::sm_getActiveHighlightedTextColorMID = 0;
jmethodID QStyleManager::sm_getInactiveHighlightedTextColorMID = 0;
jmethodID QStyleManager::sm_getDisabledHighlightedTextColorMID = 0;
jmethodID QStyleManager::sm_getActiveLinkColorMID = 0;
jmethodID QStyleManager::sm_getInactiveLinkColorMID = 0;
jmethodID QStyleManager::sm_getDisabledLinkColorMID = 0;
jmethodID QStyleManager::sm_getActiveLinkVisitedColorMID = 0;
jmethodID QStyleManager::sm_getInactiveLinkVisitedColorMID = 0;
jmethodID QStyleManager::sm_getDisabledLinkVisitedColorMID = 0;
jmethodID QStyleManager::sm_getDefaultFontMID = 0;
jmethodID QStyleManager::sm_getFixedFontMID = 0;
jmethodID QStyleManager::sm_getComponentFontMID = 0;
jmethodID QStyleManager::sm_getButtonFontMID = 0;
jmethodID QStyleManager::sm_getMenuFontMID = 0;
jmethodID QStyleManager::sm_getMenuBarFontMID = 0;
jmethodID QStyleManager::sm_getTextFontMID = 0;
jmethodID QStyleManager::sm_getToolTipFontMID = 0;

